import java.awt.Dimension;
import java.awt.Font;
import java.util.ArrayList;
import java.util.Random;

import java.awt.EventQueue;
import javax.swing.JFrame;
import java.awt.BorderLayout;
import javax.swing.JPanel;
import javax.swing.JLabel;
import javax.swing.SwingConstants;
import java.awt.Component;
import javax.swing.Box;
import java.awt.GridLayout;
import javax.swing.JButton;
import javax.swing.JTabbedPane;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import javax.swing.JTable;


/**
 * This class represents the main GUI that we will create in the game. This GUI houses all the in game components
 * like the ShortRangeChart, Shipyard, Marketplace, and SolarSystem information.
 * @author Araya Zaesim, Stanley Ayzenberg, Michelle Partogi, Adam Perez
 * @version 1.0
*/

public class SpaceTraderGui {
	
	private JFrame frame;
	private JTable table_1;
	private Player player;
	private ArrayList<SolarSystem> universe;
	private JLabel lblPlayername;
	private JPanel mainPanel;
	private JPanel northPanel;
	private JPanel topMenuPanel;
	private JButton btnNewGame;
	private JButton btnSaveGame;
	private JButton btnLoadGame;
	private JPanel infoPanel;
	private JLabel lblSolarSystem;
	private JLabel lblCredits;
	private JTabbedPane tabbedPane;
	private JPanel panel_7;
	private JPanel curSSPanel;
	private JPanel curSSPanel_1;
	private JPanel systemPanel;
	private JLabel lblSolarSystem2;
	private JLabel lblSolarSystem2_1;
	private JLabel lblCurrentSystem;
	private JLabel lblResource;
	private JLabel lblResource_1;
	private JLabel lblGovernment;
	private JLabel lblGovernment_1;
	private JLabel lblPolice;
	private JLabel lblPolice_1;
	private JLabel lblPirates;
	private JLabel lblPirates_1;
	private JLabel lblDistance;
	private JLabel lblDistance_1;
	private JLabel lblTechLevel;
	private JLabel lblTechLevel_1;
	private JLabel lblSizeTiny;
	private JLabel lblSizeTiny_1;
	private JPanel panel_3;
	private JPanel panel_2;
	private JPanel panel_8;
	private JLabel label;
	private JLabel label_1;
	private JButton button;
	private JLabel lblShipyard;
	private JButton btnNewButton;
	private JLabel label_2;
	private JLabel label_3;
	private JButton button_1;
	private JLabel label_4;
	private JButton button_2;
	private JButton btnSellWater;
	private JButton btnSellFurs;
	private JButton btnSellFood;
	private JButton btnSellOre;
	private JButton btnSellGames;
	private JButton btnSellFirearms;
	private JButton btnSellMedicine;
	private JButton btnSellMachines;
	private JButton btnSellNarcotics;
	private JButton btnSellRobots;
	private JButton btnSellAllWater;
	private JButton btnSellAllFurs;
	private JButton btnSellAllFood;
	private JButton btnSellAllOre;
	private JButton btnSellAllGames;
	private JButton btnSellAllFirearms;
	private JButton btnSellAllMedicine;
	private JButton btnSellAllMachines;
	private JButton btnSellAllNarcotics;
	private JButton btnSellAllRobots;
	private JLabel lblWaterPrice;
	private JLabel lblFursPrice;
	private JLabel lblFoodPrice;
	private JLabel lblOrePrice;
	private JLabel lblGamesPrice;
	private JLabel lblFirearmsPrice;
	private JLabel lblMedicinePrice;
	private JLabel lblMachinesPrice;
	private JLabel lblNarcoticsPrice;
	private JLabel lblRobotsPrice;
	private JButton btnBuyWater;
	private JButton btnBuyFurs;
	private JButton btnBuyFood;
	private JButton btnBuyOre;
	private JButton btnBuyGames;
	private JButton btnBuyFirearms;
	private JButton btnBuyMedicine;
	private JButton btnBuyMachines;
	private JButton btnBuyNarcotics;
	private JButton btnBuyRobots;
	private JButton btnBuyAllWater;
	private JButton btnBuyAllFurs;
	private JButton btnBuyAllFood;
	private JButton btnBuyAllOre;
	private JButton btnBuyAllGames;
	private JButton btnBuyAllFirearms;
	private JButton btnBuyAllMedicine;
	private JButton btnBuyAllMachines;
	private JButton btnBuyAllNarcotics;
	private JButton btnBuyAllRobots;
	private JButton btnWarp;
	private JLabel lblWaterCost;
	private JLabel lblFursCost;
	private JLabel lblFoodCost;
	private JLabel lblOreCost;
	private JLabel lblGamesCost;
	private JLabel lblFirearmsCost;
	private JLabel lblMedicineCost;
	private JLabel lblMachinesCost;
	private JLabel lblNarcoticsCost;
	private JLabel lblRobotsCost;
	private SolarSystem currentSystem = null;
	private SolarSystem targetSystem = null;
	private MarketPlaceLogic mpLogic;
	private int[] buyPrices = new int[10];
	private int[] sellPrices = new int[10];
	private JLabel lblCurrentSolarSystem;
	private JLabel lblResource_2;
	private JLabel lblGovernment_2;
	private JLabel lblPolice_2;
	private JLabel lblPirates_2;
	private JLabel lblTechLevel_2;
	private JLabel lblSize;
	private JLabel lblFuelLevel;
	private ShortRangeChart chartPanel;

	
	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					SpaceTraderGui window = new SpaceTraderGui();					
					window.frame.setVisible(true);

				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the application.
	 * Also creates the universe with allSystems.
	 */
	public SpaceTraderGui() {
		initialize();
		Universe un = new Universe();
		universe = un.getSystems();
	}

	/**
	 * Initialize the contents of the frame.
	 */
	private void initialize() {
		frame = new JFrame();
		frame.setResizable(false);
		frame.setPreferredSize(new Dimension(1200, 1200) );
		frame.setBounds(1000, 100, 950, 650);
		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		frame.getContentPane().setLayout(new BorderLayout(0, 0));
		
		mainPanel = new JPanel();
		frame.getContentPane().add(mainPanel, BorderLayout.CENTER);
		mainPanel.setLayout(new BorderLayout(0, 0));
		
		
		northPanel = new JPanel();
		mainPanel.add(northPanel, BorderLayout.NORTH);
		northPanel.setLayout(new GridLayout(2, 0, 0, 0));
		
		topMenuPanel = new JPanel();
		northPanel.add(topMenuPanel);
		
		btnNewGame = new JButton("New Game");
		btnNewGame.addActionListener(new ActionListener() {
			
			/*
			 * Creates a config window when New Game is pressed so that a user can enter skill points, name, and choose a
			 * difficulty.
			 */
			public void actionPerformed(ActionEvent e) {
				ConfigWindow window = new ConfigWindow(getGui());						
			}
		});
		topMenuPanel.add(btnNewGame);
		
		btnSaveGame = new JButton("Save Game");
		topMenuPanel.add(btnSaveGame);
		
		btnLoadGame = new JButton("Load Game");
		topMenuPanel.add(btnLoadGame);
		
		infoPanel = new JPanel();
		northPanel.add(infoPanel);
		
		lblSolarSystem = new JLabel("Solar System: ");
		infoPanel.add(lblSolarSystem);
		
		Component horizontalStrut = Box.createHorizontalStrut(60);
		infoPanel.add(horizontalStrut);
		lblPlayername = new JLabel("Player: ");
		infoPanel.add(lblPlayername);
		lblPlayername.setHorizontalAlignment(SwingConstants.RIGHT);
		
		Component horizontalStrut_1 = Box.createHorizontalStrut(60);
		infoPanel.add(horizontalStrut_1);
		
		lblCredits = new JLabel("Credits: ");
		infoPanel.add(lblCredits);
		
		tabbedPane = new JTabbedPane(JTabbedPane.TOP);
		mainPanel.add(tabbedPane, BorderLayout.CENTER);
		
		JPanel panel_7 = new JPanel();
		tabbedPane.addTab("Marketplace", null, panel_7, null);
		
		String[] columnNames = {"First Name",
                "Last Name",
                "Sport",
                "# of Years",
                "Vegetarian"};

		Object[][] data = {
				{"Water", "Water BP", "Water Buy","Water SP", "Water Sell"} ,
				{"Ore", "Ore BP", "Ore Buy", "Ore SP", "Ore Sell"},
				{"Food", "Food BP", "Food Buy", "Food SP", "Food Sell"},
				{"Ore", "Ore BP", "Ore Buy", "Ore SP", "Ore Sell"},
				{"Game", "Game BP", "Game Buy", "Game SP", "Game Sell"},
				{"Firearm", "Firearm BP", "Firearm Buy", "Firearm SP", "Firearm Sell"},
				{"Medicine", "Medicine BP", "Medicine Buy", "Medicine SP", "Medicine Sell"},
				{"Machine", "Machine BP", "Machine Buy", "Machine SP", "Machine Sell"},
				{"Narcotics", "Narcotics BP", "Narcotics Buy", "Narcotics SP", "Narcotics Sell"},
				{"Robots", "Robots BP", "Robots Buy", "Robots SP", "Robots Sell"}
		};
		panel_7.setLayout(null);
		
		curSSPanel = new JPanel();
		curSSPanel.setBounds(0, 0, 0, 0);
		panel_7.add(curSSPanel);
		curSSPanel.setLayout(new GridLayout(0, 2, 0, 0));
		
		JLabel lblCurSystem = new JLabel("Current Solar System Marketplace");
		curSSPanel.add(lblCurSystem);
	
		
		table_1 = new JTable(data, columnNames);
		curSSPanel.add(table_1);
		//table_1.setRowMargin(30);
		table_1.setRowHeight(25);
		table_1.setPreferredScrollableViewportSize(new Dimension(500, 70));
		table_1.setFillsViewportHeight(true);
		
		
		
		systemPanel = new JPanel();
		systemPanel.setBounds(0, 0, 0, 0);
		panel_7.add(systemPanel);
		systemPanel.setLayout(new GridLayout(10, 0, 0, 0));
		
		lblSolarSystem2 = new JLabel("Target Solar System: ");
		systemPanel.add(lblSolarSystem2);
		
		lblCurrentSystem = new JLabel("Andromeda System");
		systemPanel.add(lblCurrentSystem);
		
		lblResource = new JLabel("Resource: ______");
		systemPanel.add(lblResource);
		
		lblGovernment = new JLabel("Government: ______");
		systemPanel.add(lblGovernment);
		
		lblPolice = new JLabel("Police: _____");
		systemPanel.add(lblPolice);
		
		lblPirates = new JLabel("Pirates: _____");
		systemPanel.add(lblPirates);
		
		lblDistance = new JLabel("Distance: ____");
		systemPanel.add(lblDistance);
		
		lblTechLevel = new JLabel("Tech Level: ______");
		systemPanel.add(lblTechLevel);
		
		lblSizeTiny = new JLabel("Size: Tiny");
		systemPanel.add(lblSizeTiny);
		
		
		
		panel_3 = new JPanel();
		panel_3.setBounds(0, 0, 0, 0);
		panel_7.add(panel_3);


		
		panel_8 = new JPanel();
		tabbedPane.addTab("Marketplace", null, panel_7, null);
		tabbedPane.addTab("Shipyard ", null, panel_8, null);
		
		JPanel shipYardPanel = new JPanel();
		panel_8.add(shipYardPanel);
		shipYardPanel.setLayout(new GridLayout(5, 0, 0, 0));
		
		label = new JLabel("Shipyard");
		shipYardPanel.add(label);
		
		label_1 = new JLabel("___ Ships Available");
		shipYardPanel.add(label_1);
		
		button = new JButton("Buy Ship");
		shipYardPanel.add(button);
		
		lblShipyard = new JLabel("Equipment Merchant");
		shipYardPanel.add(lblShipyard);
		
		btnNewButton = new JButton("Buy/Sell Equipment");
		btnNewButton.addActionListener(new ActionListener() {
			/*
			 * Pops up a window for buying or selling equipment for a player's Spaceship
			 */
			public void actionPerformed(ActionEvent e) {
			}
		});
		shipYardPanel.add(btnNewButton);
		
		panel_2 = new JPanel();
		panel_8.add(panel_2);
		panel_2.setLayout(new GridLayout(5,0 , 0, 0));
		
		label_2 = new JLabel("Dock");
		panel_2.add(label_2);
		
		label_3 = new JLabel("<html><pre>You have ___ Parcels of Fuel. \n A full tank costs ____.</html></pre>");
		panel_2.add(label_3);
		
		button_1 = new JButton("Fill Tank");
		panel_2.add(button_1);
		
		label_4 = new JLabel("<html><pre>Your Hull Strength ___% \n __Credits for repairs.</html></pre>");
		panel_2.add(label_4);
		
		button_2 = new JButton("Repair Hull");
		panel_2.add(button_2);
		
		//tabbedPane.addTab("Marketplace", null, panel_7, null);
		panel_7.setLayout(null);
		
		curSSPanel_1 = new JPanel();
		curSSPanel_1.setBounds(0, 0, 943, 340);
		panel_7.add(curSSPanel_1);
		curSSPanel_1.setLayout(null);
		
		JLabel lblBuy = new JLabel("Buy");
		lblBuy.setBounds(435, 5, 50, 20);
		curSSPanel_1.add(lblBuy);
		
		JLabel lblSell = new JLabel("Sell");
		lblSell.setBounds(185, 5, 50, 20);
		curSSPanel_1.add(lblSell);
		
		JLabel lblWater = new JLabel("Water");
		lblWater.setBounds(15, 40, 55, 15);
		curSSPanel_1.add(lblWater);
		
		JLabel lblFurs = new JLabel("Furs");
		lblFurs.setBounds(15, 70, 55, 15);
		curSSPanel_1.add(lblFurs);
		
		JLabel lblFood = new JLabel("Food");
		lblFood.setBounds(15, 100, 55, 15);
		curSSPanel_1.add(lblFood);
		
		JLabel lblOres = new JLabel("Ore");
		lblOres.setBounds(15, 130, 55, 15);
		curSSPanel_1.add(lblOres);
		
		JLabel lblGames = new JLabel("Games");
		lblGames.setBounds(15, 160, 55, 15);
		curSSPanel_1.add(lblGames);
		
		JLabel lblFirearms = new JLabel("Firearms");
		lblFirearms.setBounds(15, 190, 55, 14);
		curSSPanel_1.add(lblFirearms);
		
		JLabel lblMedicine = new JLabel("Medicine");
		lblMedicine.setBounds(15, 220, 55, 14);
		curSSPanel_1.add(lblMedicine);
		
		JLabel lblMachines = new JLabel("Machines");
		lblMachines.setBounds(15, 250, 55, 14);
		curSSPanel_1.add(lblMachines);
		
		JLabel lblNarcotics = new JLabel("Narcotics");
		lblNarcotics.setBounds(15, 280, 55, 14);
		curSSPanel_1.add(lblNarcotics);
		
		JLabel lblRobots = new JLabel("Robots");
		lblRobots.setBounds(15, 310, 55, 14);
		curSSPanel_1.add(lblRobots);
		
		btnSellWater = new JButton("0");
		btnSellWater.setBounds(100, 37, 50, 23);
		curSSPanel_1.add(btnSellWater);
		btnSellWater.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				int[] tempGoods = player.getShip().getGoods();
				int[] tempGoods2 = currentSystem.getGoods();
				if (tempGoods[0] > 0 && Goods.WATER.getMTLU() <= currentSystem.getTechLevel() ) {
					tempGoods[0] -= 1;
					tempGoods2[0] += 1;
					currentSystem.setGoods(tempGoods2);
					player.getShip().setGoods(tempGoods);
					player.getShip().setCargo(player.getShip().getCargo() -1);
					player.setCredits(player.getCredits() + sellPrices[0]);
					updateMarketPlace(player);
				}
			}
		});
		
		btnSellFurs = new JButton("0");
		btnSellFurs.setBounds(100, 67, 50, 23);
		curSSPanel_1.add(btnSellFurs);
		btnSellFurs.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				int[] tempGoods = player.getShip().getGoods();
				int[] tempGoods2 = currentSystem.getGoods();
				if (tempGoods[1] > 0 && Goods.FURS.getMTLU() <= currentSystem.getTechLevel() ) {
					tempGoods[1] -= 1;
					tempGoods2[1] += 1;
					currentSystem.setGoods(tempGoods2);
					player.getShip().setGoods(tempGoods);
					player.getShip().setCargo(player.getShip().getCargo() -1);
					player.setCredits(player.getCredits() + sellPrices[1]);
					updateMarketPlace(player);
				}
			}
		});
		
		btnSellFood = new JButton("0");
		btnSellFood.setBounds(100, 97, 50, 23);
		curSSPanel_1.add(btnSellFood);
		btnSellFood.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				int[] tempGoods = player.getShip().getGoods();
				int[] tempGoods2 = currentSystem.getGoods();
				if (tempGoods[2] > 0 && Goods.FOOD.getMTLU() <= currentSystem.getTechLevel() ) {
					tempGoods[2] -= 1;
					tempGoods2[2] += 1;
					currentSystem.setGoods(tempGoods2);
					player.getShip().setGoods(tempGoods);
					player.getShip().setCargo(player.getShip().getCargo() -1);
					player.setCredits(player.getCredits() + sellPrices[2]);
					updateMarketPlace(player);
				}
			}
		});
		
		btnSellOre = new JButton("0");
		btnSellOre.setBounds(100, 127, 50, 23);
		curSSPanel_1.add(btnSellOre);
		btnSellOre.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				int[] tempGoods = player.getShip().getGoods();
				int[] tempGoods2 = currentSystem.getGoods();
				if (tempGoods[3] > 0 && Goods.ORE.getMTLU() <= currentSystem.getTechLevel() ) {
					tempGoods[3] -= 1;
					tempGoods2[3] += 1;
					currentSystem.setGoods(tempGoods2);
					player.getShip().setGoods(tempGoods);
					player.getShip().setCargo(player.getShip().getCargo() -1);
					player.setCredits(player.getCredits() + sellPrices[3]);
					updateMarketPlace(player);
				}
			}
		});
		
		btnSellGames = new JButton("0");
		btnSellGames.setBounds(100, 157, 50, 23);
		curSSPanel_1.add(btnSellGames);
		btnSellGames.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				int[] tempGoods = player.getShip().getGoods();
				int[] tempGoods2 = currentSystem.getGoods();
				if (tempGoods[4] > 0 && Goods.GAMES.getMTLU() <= currentSystem.getTechLevel() ) {
					tempGoods[4] -= 1;
					tempGoods2[4] += 1;
					currentSystem.setGoods(tempGoods2);
					player.getShip().setGoods(tempGoods);
					player.getShip().setCargo(player.getShip().getCargo() -1);
					player.setCredits(player.getCredits() + sellPrices[4]);
					updateMarketPlace(player);
				}
			}
		});
		
		btnSellFirearms = new JButton("0");
		btnSellFirearms.setBounds(100, 187, 50, 23);
		curSSPanel_1.add(btnSellFirearms);
		btnSellFirearms.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				int[] tempGoods = player.getShip().getGoods();
				int[] tempGoods2 = currentSystem.getGoods();
				if (tempGoods[5] > 0 && Goods.FIREARMS.getMTLU() <= currentSystem.getTechLevel() ) {
					tempGoods[5] -= 1;
					tempGoods2[5] += 1;
					currentSystem.setGoods(tempGoods2);
					player.getShip().setGoods(tempGoods);
					player.getShip().setCargo(player.getShip().getCargo() -1);
					player.setCredits(player.getCredits() + sellPrices[5]);
					updateMarketPlace(player);
				}
			}
		});
		
		btnSellMedicine = new JButton("0");
		btnSellMedicine.setBounds(100, 217, 50, 23);
		curSSPanel_1.add(btnSellMedicine);
		btnSellMedicine.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				int[] tempGoods = player.getShip().getGoods();
				int[] tempGoods2 = currentSystem.getGoods();
				if (tempGoods[6] > 0 && Goods.MEDICINE.getMTLU() <= currentSystem.getTechLevel() ) {
					tempGoods[6] -= 1;
					tempGoods2[6] += 1;
					currentSystem.setGoods(tempGoods2);
					player.getShip().setGoods(tempGoods);
					player.getShip().setCargo(player.getShip().getCargo() -1);
					player.setCredits(player.getCredits() + sellPrices[6]);
					updateMarketPlace(player);
				}
			}
		});
		
		btnSellMachines = new JButton("0");
		btnSellMachines.setBounds(100, 247, 50, 23);
		curSSPanel_1.add(btnSellMachines);
		btnSellMachines.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				int[] tempGoods = player.getShip().getGoods();
				int[] tempGoods2 = currentSystem.getGoods();
				if (tempGoods[7] > 0 && Goods.MACHINES.getMTLU() <= currentSystem.getTechLevel() ) {
					tempGoods[7] -= 1;
					tempGoods2[7] += 1;
					currentSystem.setGoods(tempGoods2);
					player.getShip().setGoods(tempGoods);
					player.getShip().setCargo(player.getShip().getCargo() -1);
					player.setCredits(player.getCredits() + sellPrices[7]);
					updateMarketPlace(player);
				}
			}
		});
		
		btnSellNarcotics = new JButton("0");
		btnSellNarcotics.setBounds(100, 277, 50, 23);
		curSSPanel_1.add(btnSellNarcotics);
		btnSellNarcotics.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				int[] tempGoods = player.getShip().getGoods();
				int[] tempGoods2 = currentSystem.getGoods();
				if (tempGoods[8] > 0 && Goods.NARCOTICS.getMTLU() <= currentSystem.getTechLevel() ) {
					tempGoods[8] -= 1;
					tempGoods2[8] += 1;
					currentSystem.setGoods(tempGoods2);
					player.getShip().setGoods(tempGoods);
					player.getShip().setCargo(player.getShip().getCargo() -1);
					player.setCredits(player.getCredits() + sellPrices[8]);
					updateMarketPlace(player);
				}
			}
		});
		
		btnSellRobots = new JButton("0");
		btnSellRobots.setBounds(100, 307, 50, 23);
		curSSPanel_1.add(btnSellRobots);
		btnSellRobots.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				int[] tempGoods = player.getShip().getGoods();
				int[] tempGoods2 = currentSystem.getGoods();
				if (tempGoods[9] > 0 && Goods.ROBOTS.getMTLU() <= currentSystem.getTechLevel() ) {
					tempGoods[9] -= 1;
					tempGoods2[9] += 1;
					currentSystem.setGoods(tempGoods2);
					player.getShip().setGoods(tempGoods);
					player.getShip().setCargo(player.getShip().getCargo() -1);
					player.setCredits(player.getCredits() + sellPrices[9]);
					updateMarketPlace(player);
				}
			}
		});
		
		btnSellAllWater = new JButton("All");
		btnSellAllWater.setBounds(160, 37, 70, 23);
		curSSPanel_1.add(btnSellAllWater);
		btnSellAllWater.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				int[] tempGoods = player.getShip().getGoods();
				int[] tempGoods2 = currentSystem.getGoods();
				while (tempGoods[0] > 0 && Goods.WATER.getMTLU() <= currentSystem.getTechLevel() ) {
					tempGoods[0] -= 1;
					tempGoods2[0] += 1;
					currentSystem.setGoods(tempGoods2);
					player.getShip().setGoods(tempGoods);
					player.getShip().setCargo(player.getShip().getCargo() -1);
					player.setCredits(player.getCredits() + sellPrices[0]);
				}
				updateMarketPlace(player);
			}
		});
		
		btnSellAllFurs = new JButton("All");
		btnSellAllFurs.setBounds(160, 67, 70, 23);
		curSSPanel_1.add(btnSellAllFurs);
		btnSellAllFurs.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				int[] tempGoods = player.getShip().getGoods();
				int[] tempGoods2 = currentSystem.getGoods();
				while (tempGoods[1] > 0 && Goods.FURS.getMTLU() <= currentSystem.getTechLevel() ) {
					tempGoods[1] -= 1;
					tempGoods2[1] += 1;
					currentSystem.setGoods(tempGoods2);
					player.getShip().setGoods(tempGoods);
					player.getShip().setCargo(player.getShip().getCargo() -1);
					player.setCredits(player.getCredits() + sellPrices[1]);
				}
				updateMarketPlace(player);
			}
		});
		
		btnSellAllFood = new JButton("All");
		btnSellAllFood.setBounds(160, 97, 70, 23);
		curSSPanel_1.add(btnSellAllFood);
		btnSellAllFood.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				int[] tempGoods = player.getShip().getGoods();
				int[] tempGoods2 = currentSystem.getGoods();
				while (tempGoods[2] > 0 && Goods.FOOD.getMTLU() <= currentSystem.getTechLevel() ) {
					tempGoods[2] -= 1;
					tempGoods2[2] += 1;
					currentSystem.setGoods(tempGoods2);
					player.getShip().setGoods(tempGoods);
					player.getShip().setCargo(player.getShip().getCargo() -1);
					player.setCredits(player.getCredits() + sellPrices[2]);
				}
				updateMarketPlace(player);
			}
		});
		
		btnSellAllOre = new JButton("All");
		btnSellAllOre.setBounds(160, 127, 70, 23);
		curSSPanel_1.add(btnSellAllOre);
		btnSellAllOre.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				int[] tempGoods = player.getShip().getGoods();
				int[] tempGoods2 = currentSystem.getGoods();
				while (tempGoods[3] > 0 && Goods.ORE.getMTLU() <= currentSystem.getTechLevel() ) {
					tempGoods[3] -= 1;
					tempGoods2[3] += 1;
					currentSystem.setGoods(tempGoods2);
					player.getShip().setGoods(tempGoods);
					player.getShip().setCargo(player.getShip().getCargo() -1);
					player.setCredits(player.getCredits() + sellPrices[3]);
				}
				updateMarketPlace(player);
			}
		});
		
		btnSellAllGames = new JButton("All");
		btnSellAllGames.setBounds(160, 157, 70, 23);
		curSSPanel_1.add(btnSellAllGames);
		btnSellAllGames.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				int[] tempGoods = player.getShip().getGoods();
				int[] tempGoods2 = currentSystem.getGoods();
				while (tempGoods[4] > 0 && Goods.GAMES.getMTLU() <= currentSystem.getTechLevel() ) {
					tempGoods[4] -= 1;
					tempGoods2[4] += 1;
					currentSystem.setGoods(tempGoods2);
					player.getShip().setGoods(tempGoods);
					player.getShip().setCargo(player.getShip().getCargo() -1);
					player.setCredits(player.getCredits() + sellPrices[4]);
				}
				updateMarketPlace(player);
			}
		});
		
		btnSellAllFirearms = new JButton("All");
		btnSellAllFirearms.setBounds(160, 187, 70, 23);
		curSSPanel_1.add(btnSellAllFirearms);
		btnSellAllFirearms.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				int[] tempGoods = player.getShip().getGoods();
				int[] tempGoods2 = currentSystem.getGoods();
				while (tempGoods[5] > 0 && Goods.FIREARMS.getMTLU() <= currentSystem.getTechLevel() ) {
					tempGoods[5] -= 1;
					tempGoods2[5] += 1;
					currentSystem.setGoods(tempGoods2);
					player.getShip().setGoods(tempGoods);
					player.getShip().setCargo(player.getShip().getCargo() -1);
					player.setCredits(player.getCredits() + sellPrices[5]);
				}
				updateMarketPlace(player);
			}
		});
		
		btnSellAllMedicine = new JButton("All");
		btnSellAllMedicine.setBounds(160, 217, 70, 23);
		curSSPanel_1.add(btnSellAllMedicine);
		btnSellAllMedicine.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				int[] tempGoods = player.getShip().getGoods();
				int[] tempGoods2 = currentSystem.getGoods();
				while (tempGoods[6] > 0 && Goods.MEDICINE.getMTLU() <= currentSystem.getTechLevel() ) {
					tempGoods[6] -= 1;
					tempGoods2[6] += 1;
					currentSystem.setGoods(tempGoods2);
					player.getShip().setGoods(tempGoods);
					player.getShip().setCargo(player.getShip().getCargo() -1);
					player.setCredits(player.getCredits() + sellPrices[6]);
				}
				updateMarketPlace(player);
			}
		});
		
		btnSellAllMachines = new JButton("All");
		btnSellAllMachines.setBounds(160, 247, 70, 23);
		curSSPanel_1.add(btnSellAllMachines);
		btnSellAllMachines.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				int[] tempGoods = player.getShip().getGoods();
				int[] tempGoods2 = currentSystem.getGoods();
				while (tempGoods[7] > 0 && Goods.MACHINES.getMTLU() <= currentSystem.getTechLevel() ) {
					tempGoods[7] -= 1;
					tempGoods2[7] += 1;
					currentSystem.setGoods(tempGoods2);
					player.getShip().setGoods(tempGoods);
					player.getShip().setCargo(player.getShip().getCargo() -1);
					player.setCredits(player.getCredits() + sellPrices[7]);
				}
				updateMarketPlace(player);
			}
		});
		
		btnSellAllNarcotics = new JButton("All");
		btnSellAllNarcotics.setBounds(160, 277, 70, 23);
		curSSPanel_1.add(btnSellAllNarcotics);
		btnSellAllNarcotics.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				int[] tempGoods = player.getShip().getGoods();
				int[] tempGoods2 = currentSystem.getGoods();
				while (tempGoods[8] > 0  && Goods.NARCOTICS.getMTLU() <= currentSystem.getTechLevel() ) {
					tempGoods[8] -= 1;
					tempGoods2[8] += 1;
					currentSystem.setGoods(tempGoods2);
					player.getShip().setGoods(tempGoods);
					player.getShip().setCargo(player.getShip().getCargo() -1);
					player.setCredits(player.getCredits() + sellPrices[8]);
				}
				updateMarketPlace(player);
			}
		});
		
		btnSellAllRobots = new JButton("All");
		btnSellAllRobots.setBounds(160, 307, 70, 23);
		curSSPanel_1.add(btnSellAllRobots);
		btnSellAllRobots.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				int[] tempGoods = player.getShip().getGoods();
				int[] tempGoods2 = currentSystem.getGoods();
				while (tempGoods[9] > 0 && Goods.ROBOTS.getMTLU() <= currentSystem.getTechLevel() ) {
					tempGoods[9] -= 1;
					tempGoods2[9] += 1;
					currentSystem.setGoods(tempGoods2);
					player.getShip().setGoods(tempGoods);
					player.getShip().setCargo(player.getShip().getCargo() -1);
					player.setCredits(player.getCredits() + sellPrices[9]);
				}
				updateMarketPlace(player);
			}
		});
		
		lblWaterPrice = new JLabel("");
		lblWaterPrice.setBounds(240, 40, 75, 15);
		curSSPanel_1.add(lblWaterPrice);
		
		lblFursPrice = new JLabel("");
		lblFursPrice.setBounds(240, 70, 75, 15);
		curSSPanel_1.add(lblFursPrice);
		
		lblFoodPrice = new JLabel("");
		lblFoodPrice.setBounds(240, 100, 75, 15);
		curSSPanel_1.add(lblFoodPrice);
		
		lblOrePrice = new JLabel("");
		lblOrePrice.setBounds(240, 130, 75, 15);
		curSSPanel_1.add(lblOrePrice);
		
		lblGamesPrice = new JLabel("");
		lblGamesPrice.setBounds(240, 160, 75, 15);
		curSSPanel_1.add(lblGamesPrice);
		
		lblFirearmsPrice = new JLabel("");
		lblFirearmsPrice.setBounds(240, 190, 75, 15);
		curSSPanel_1.add(lblFirearmsPrice);
		
		lblMedicinePrice = new JLabel("");
		lblMedicinePrice.setBounds(240, 220, 75, 15);
		curSSPanel_1.add(lblMedicinePrice);
		
		lblMachinesPrice = new JLabel("");
		lblMachinesPrice.setBounds(240, 250, 75, 15);
		curSSPanel_1.add(lblMachinesPrice);
		
		lblNarcoticsPrice = new JLabel("");
		lblNarcoticsPrice.setBounds(240, 280, 75, 15);
		curSSPanel_1.add(lblNarcoticsPrice);
		
		lblRobotsPrice = new JLabel("");
		lblRobotsPrice.setBounds(240, 310, 75, 15);
		curSSPanel_1.add(lblRobotsPrice);
		
		btnBuyWater = new JButton("0");
		btnBuyWater.setBounds(350, 37, 50, 23);
		curSSPanel_1.add(btnBuyWater);
		btnBuyWater.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				int[] tempGoods = player.getShip().getGoods();
				int[] tempGoods2 = currentSystem.getGoods();
				if (player.getShip().isFull()!= true && player.getCredits() >= buyPrices[0] && tempGoods2[0] > 0) { //ADD PRICE for credits
					tempGoods[0] += 1;
					tempGoods2[0] -= 1;
					player.getShip().setGoods(tempGoods);
					player.getShip().setCargo(player.getShip().getCargo() +1);
					currentSystem.setGoods(tempGoods2);
					player.setCredits(player.getCredits() - buyPrices[0]);
					updateMarketPlace(player);
				}
			}
		});
		
		btnBuyFurs = new JButton("0");
		btnBuyFurs.setBounds(350, 67, 50, 23);
		curSSPanel_1.add(btnBuyFurs);
		btnBuyFurs.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				int[] tempGoods = player.getShip().getGoods();
				int[] tempGoods2 = currentSystem.getGoods();
				if (player.getShip().isFull()!= true && player.getCredits() >= buyPrices[1] && tempGoods2[1] > 0) { //ADD PRICE for credits
					tempGoods[1] += 1;
					tempGoods2[1] -= 1;
					player.getShip().setGoods(tempGoods);
					player.getShip().setCargo(player.getShip().getCargo() +1);
					currentSystem.setGoods(tempGoods2);
					player.setCredits(player.getCredits() - buyPrices[1]);
					updateMarketPlace(player);
				}
			}
		});
		
		btnBuyFood = new JButton("0");
		btnBuyFood.setBounds(350, 97, 50, 23);
		curSSPanel_1.add(btnBuyFood);
		btnBuyFood.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				int[] tempGoods = player.getShip().getGoods();
				int[] tempGoods2 = currentSystem.getGoods();
				if (player.getShip().isFull()!= true && player.getCredits() >= buyPrices[2] && tempGoods2[2] > 0) { //ADD PRICE for credits
					tempGoods[2] += 1;
					tempGoods2[2] -= 1;
					player.getShip().setGoods(tempGoods);
					player.getShip().setCargo(player.getShip().getCargo() +1);
					currentSystem.setGoods(tempGoods2);
					player.setCredits(player.getCredits() - buyPrices[1]);
					updateMarketPlace(player);
				}
			}
		});
		
		btnBuyOre = new JButton("0");
		btnBuyOre.setBounds(350, 127, 50, 23);
		curSSPanel_1.add(btnBuyOre);
		btnBuyOre.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				int[] tempGoods = player.getShip().getGoods();
				int[] tempGoods2 = currentSystem.getGoods();
				if (player.getShip().isFull()!= true && player.getCredits() >= buyPrices[3] && tempGoods2[3] > 0) { //ADD PRICE for credits
					tempGoods[3] += 1;
					tempGoods2[3] -= 1;
					player.getShip().setGoods(tempGoods);
					player.getShip().setCargo(player.getShip().getCargo() +1);
					currentSystem.setGoods(tempGoods2);
					player.setCredits(player.getCredits() - buyPrices[3]);
					updateMarketPlace(player);
				}
			}
		});
		
		btnBuyGames = new JButton("0");
		btnBuyGames.setBounds(350, 157, 50, 23);
		curSSPanel_1.add(btnBuyGames);
		btnBuyGames.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				int[] tempGoods = player.getShip().getGoods();
				int[] tempGoods2 = currentSystem.getGoods();
				if (player.getShip().isFull()!= true && player.getCredits() >= buyPrices[4] && tempGoods2[4] > 0) { //ADD PRICE for credits
					tempGoods[4] += 1;
					tempGoods2[4] -= 1;
					player.getShip().setGoods(tempGoods);
					player.getShip().setCargo(player.getShip().getCargo() +1);
					currentSystem.setGoods(tempGoods2);
					player.setCredits(player.getCredits() - buyPrices[4]);
					updateMarketPlace(player);
				}
			}
		});
		
		btnBuyFirearms = new JButton("0");
		btnBuyFirearms.setBounds(350, 187, 50, 23);
		curSSPanel_1.add(btnBuyFirearms);
		btnBuyFirearms.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				int[] tempGoods = player.getShip().getGoods();
				int[] tempGoods2 = currentSystem.getGoods();
				if (player.getShip().isFull()!= true && player.getCredits() >= buyPrices[5] && tempGoods2[5] > 0) { //ADD PRICE for credits
					tempGoods[5] += 1;
					tempGoods2[5] -= 1;
					player.getShip().setGoods(tempGoods);
					player.getShip().setCargo(player.getShip().getCargo() +1);
					currentSystem.setGoods(tempGoods2);
					player.setCredits(player.getCredits() - buyPrices[5]);
					updateMarketPlace(player);
				}
			}
		});
		
		btnBuyMedicine = new JButton("0");
		btnBuyMedicine.setBounds(350, 217, 50, 23);
		curSSPanel_1.add(btnBuyMedicine);
		btnBuyMedicine.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				int[] tempGoods = player.getShip().getGoods();
				int[] tempGoods2 = currentSystem.getGoods();
				if (player.getShip().isFull()!= true && player.getCredits() >= buyPrices[6] && tempGoods2[6] > 0) { //ADD PRICE for credits
					tempGoods[6] += 1;
					tempGoods2[6] -= 1;
					player.getShip().setGoods(tempGoods);
					player.getShip().setCargo(player.getShip().getCargo() +1);
					currentSystem.setGoods(tempGoods2);
					player.setCredits(player.getCredits() - buyPrices[6]);
					updateMarketPlace(player);
				}
			}
		});
		
		btnBuyMachines = new JButton("0");
		btnBuyMachines.setBounds(350, 247, 50, 23);
		curSSPanel_1.add(btnBuyMachines);
		btnBuyMachines.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				int[] tempGoods = player.getShip().getGoods();
				int[] tempGoods2 = currentSystem.getGoods();
				if (player.getShip().isFull()!= true && player.getCredits() >= buyPrices[7] && tempGoods2[7] >= 0) { //ADD PRICE for credits
					tempGoods[7] += 1;
					tempGoods2[7] -= 1;
					player.getShip().setGoods(tempGoods);
					player.getShip().setCargo(player.getShip().getCargo() +1);
					currentSystem.setGoods(tempGoods2);
					player.setCredits(player.getCredits() - buyPrices[7]);
					updateMarketPlace(player);
				}
			}
		});
		
		btnBuyNarcotics = new JButton("0");
		btnBuyNarcotics.setBounds(350, 277, 50, 23);
		curSSPanel_1.add(btnBuyNarcotics);
		btnBuyNarcotics.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				int[] tempGoods = player.getShip().getGoods();
				int[] tempGoods2 = currentSystem.getGoods();
				if (player.getShip().isFull()!= true && player.getCredits() >= buyPrices[8] && tempGoods2[8] >= 0) { //ADD PRICE for credits
					tempGoods[8] += 1;
					tempGoods2[8] -= 1;
					player.getShip().setGoods(tempGoods);
					player.getShip().setCargo(player.getShip().getCargo() +1);
					currentSystem.setGoods(tempGoods2);
					player.setCredits(player.getCredits() - buyPrices[8]);
					updateMarketPlace(player);
				}
			}
		});
		
		btnBuyRobots = new JButton("0");
		btnBuyRobots.setBounds(350, 307, 50, 23);
		curSSPanel_1.add(btnBuyRobots);
		btnBuyRobots.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				int[] tempGoods = player.getShip().getGoods();
				int[] tempGoods2 = currentSystem.getGoods();
				if (player.getShip().isFull()!= true && player.getCredits() >= buyPrices[9] && tempGoods2[9] >= 0) { //ADD PRICE for credits
					tempGoods[9] += 1;
					tempGoods2[9] -= 1;
					player.getShip().setGoods(tempGoods);
					player.getShip().setCargo(player.getShip().getCargo() +1);
					currentSystem.setGoods(tempGoods2);
					player.setCredits(player.getCredits() - buyPrices[9]);
					updateMarketPlace(player);
				}
			}
		});
		
		btnBuyAllWater = new JButton("Max");
		btnBuyAllWater.setBounds(410, 37, 70, 23);
		curSSPanel_1.add(btnBuyAllWater);
		btnBuyAllWater.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				int[] tempGoods = player.getShip().getGoods();
				int[] tempGoods2 = currentSystem.getGoods();
				while (player.getShip().isFull()!= true && player.getCredits() >= buyPrices[0] && tempGoods2[0] > 0) { //ADD PRICE for credits
					tempGoods[0] += 1;
					tempGoods2[0] -= 1;
					player.getShip().setGoods(tempGoods);
					player.getShip().setCargo(player.getShip().getCargo() +1);
					currentSystem.setGoods(tempGoods2);
					player.setCredits(player.getCredits() - buyPrices[0]);
					updateMarketPlace(player);
				}
			}
		});
		
		btnBuyAllFurs = new JButton("Max");
		btnBuyAllFurs.setBounds(410, 67, 70, 23);
		curSSPanel_1.add(btnBuyAllFurs);
		btnBuyAllFurs.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				int[] tempGoods = player.getShip().getGoods();
				int[] tempGoods2 = currentSystem.getGoods();
				while (player.getShip().isFull()!= true && player.getCredits() >= buyPrices[1] && tempGoods2[1] > 0) { //ADD PRICE for credits
					tempGoods[1] += 1;
					tempGoods2[1] -= 1;
					player.getShip().setGoods(tempGoods);
					player.getShip().setCargo(player.getShip().getCargo() +1);
					currentSystem.setGoods(tempGoods2);
					player.setCredits(player.getCredits() - buyPrices[1]);
					updateMarketPlace(player);
				}
			}
		});
		
		btnBuyAllFood = new JButton("Max");
		btnBuyAllFood.setBounds(410, 97, 70, 23);
		curSSPanel_1.add(btnBuyAllFood);
		btnBuyAllFood.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				int[] tempGoods = player.getShip().getGoods();
				int[] tempGoods2 = currentSystem.getGoods();
				while (player.getShip().isFull()!= true && player.getCredits() >= buyPrices[2] && tempGoods2[2] >0) { //ADD PRICE for credits
					tempGoods[2] += 1;
					tempGoods2[2] -= 1;
					player.getShip().setGoods(tempGoods);
					player.getShip().setCargo(player.getShip().getCargo() +1);
					currentSystem.setGoods(tempGoods2);
					player.setCredits(player.getCredits() - buyPrices[2]);
					updateMarketPlace(player);
				}
			}
		});
		
		btnBuyAllOre = new JButton("Max");
		btnBuyAllOre.setBounds(410, 127, 70, 23);
		curSSPanel_1.add(btnBuyAllOre);
		btnBuyAllOre.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				int[] tempGoods = player.getShip().getGoods();
				int[] tempGoods2 = currentSystem.getGoods();
				while (player.getShip().isFull()!= true && player.getCredits() >= buyPrices[3] && tempGoods2[3] > 0) { //ADD PRICE for credits
					tempGoods[3] += 1;
					tempGoods2[3] -= 1;
					player.getShip().setGoods(tempGoods);
					player.getShip().setCargo(player.getShip().getCargo() +1);
					currentSystem.setGoods(tempGoods2);
					player.setCredits(player.getCredits() - buyPrices[3]);
					updateMarketPlace(player);
				}
			}
		});
		
		btnBuyAllGames = new JButton("Max");
		btnBuyAllGames.setBounds(410, 157, 70, 23);
		curSSPanel_1.add(btnBuyAllGames);
		btnBuyAllGames.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				int[] tempGoods = player.getShip().getGoods();
				int[] tempGoods2 = currentSystem.getGoods();
				while (player.getShip().isFull()!= true && player.getCredits() >= buyPrices[4] && tempGoods2[4] > 0) { //ADD PRICE for credits
					tempGoods[4] += 1;
					tempGoods2[4] -= 1;
					player.getShip().setGoods(tempGoods);
					player.getShip().setCargo(player.getShip().getCargo() +1);
					currentSystem.setGoods(tempGoods2);
					player.setCredits(player.getCredits() - buyPrices[4]);
					updateMarketPlace(player);
				}
			}
		});
		
		btnBuyAllFirearms = new JButton("Max");
		btnBuyAllFirearms.setBounds(410, 187, 70, 23);
		curSSPanel_1.add(btnBuyAllFirearms);
		btnBuyAllFirearms.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				int[] tempGoods = player.getShip().getGoods();
				int[] tempGoods2 = currentSystem.getGoods();
				while (player.getShip().isFull()!= true && player.getCredits() >= buyPrices[5] && tempGoods2[5] > 0) { //ADD PRICE for credits
					tempGoods[5] += 1;
					tempGoods2[5] -= 1;
					player.getShip().setGoods(tempGoods);
					player.getShip().setCargo(player.getShip().getCargo() +1);
					currentSystem.setGoods(tempGoods2);
					player.setCredits(player.getCredits() - buyPrices[5]);
					updateMarketPlace(player);
				}
			}
		});
		
		btnBuyAllMedicine = new JButton("Max");
		btnBuyAllMedicine.setBounds(410, 217, 70, 23);
		curSSPanel_1.add(btnBuyAllMedicine);
		btnBuyAllMedicine.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				int[] tempGoods = player.getShip().getGoods();
				int[] tempGoods2 = currentSystem.getGoods();
				while (player.getShip().isFull()!= true && player.getCredits() >= buyPrices[6] && tempGoods2[6] > 0) { //ADD PRICE for credits
					tempGoods[6] += 1;
					tempGoods2[6] -= 1;
					player.getShip().setGoods(tempGoods);
					player.getShip().setCargo(player.getShip().getCargo() +1);
					currentSystem.setGoods(tempGoods2);
					player.setCredits(player.getCredits() - buyPrices[6]);
					updateMarketPlace(player);
				}
			}
		});
		
		btnBuyAllMachines = new JButton("Max");
		btnBuyAllMachines.setBounds(410, 247, 70, 23);
		curSSPanel_1.add(btnBuyAllMachines);
		btnBuyAllMachines.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				int[] tempGoods = player.getShip().getGoods();
				int[] tempGoods2 = currentSystem.getGoods();
				while (player.getShip().isFull()!= true && player.getCredits() >= buyPrices[7] && tempGoods2[7] > 0) { //ADD PRICE for credits
					tempGoods[7] += 1;
					tempGoods2[7] -= 1;
					player.getShip().setGoods(tempGoods);
					player.getShip().setCargo(player.getShip().getCargo() +1);
					currentSystem.setGoods(tempGoods2);
					player.setCredits(player.getCredits() - buyPrices[7]);
					updateMarketPlace(player);
				}
			}
		});
		
		btnBuyAllNarcotics = new JButton("Max");
		btnBuyAllNarcotics.setBounds(410, 277, 70, 23);
		curSSPanel_1.add(btnBuyAllNarcotics);
		btnBuyAllNarcotics.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				int[] tempGoods = player.getShip().getGoods();
				int[] tempGoods2 = currentSystem.getGoods();
				while (player.getShip().isFull()!= true && player.getCredits() >= buyPrices[8] && tempGoods2[8] > 0) { //ADD PRICE for credits
					tempGoods[8] += 1;
					tempGoods2[8] -= 1;
					player.getShip().setGoods(tempGoods);
					player.getShip().setCargo(player.getShip().getCargo() +1);
					currentSystem.setGoods(tempGoods2);
					player.setCredits(player.getCredits() - buyPrices[8]);
					updateMarketPlace(player);
				}
			}
		});
		
		btnBuyAllRobots = new JButton("Max");
		btnBuyAllRobots.setBounds(410, 307, 70, 23);
		curSSPanel_1.add(btnBuyAllRobots);
		btnBuyAllRobots.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				int[] tempGoods = player.getShip().getGoods();
				int[] tempGoods2 = currentSystem.getGoods();
				while (player.getShip().isFull()!= true && player.getCredits() >= buyPrices[9] && tempGoods2[9] > 0) { //ADD PRICE for credits
					tempGoods[9] += 1;
					tempGoods2[9] -= 1;
					player.getShip().setGoods(tempGoods);
					player.getShip().setCargo(player.getShip().getCargo() +1);
					currentSystem.setGoods(tempGoods2);
					player.setCredits(player.getCredits() - buyPrices[9]);
					updateMarketPlace(player);
				}
			}
		});
		
		lblWaterCost = new JLabel("");
		lblWaterCost.setBounds(490, 40, 75, 15);
		curSSPanel_1.add(lblWaterCost);
		
		lblFursCost = new JLabel("");
		lblFursCost.setBounds(490, 70, 75, 15);
		curSSPanel_1.add(lblFursCost);
		
		lblFoodCost = new JLabel("");
		lblFoodCost.setBounds(490, 100, 75, 15);
		curSSPanel_1.add(lblFoodCost);
		
		lblOreCost = new JLabel("");
		lblOreCost.setBounds(490, 130, 75, 15);
		curSSPanel_1.add(lblOreCost);
		
		lblGamesCost = new JLabel("");
		lblGamesCost.setBounds(490, 160, 75, 15);
		curSSPanel_1.add(lblGamesCost);
		
		lblFirearmsCost = new JLabel("");
		lblFirearmsCost.setBounds(490, 190, 75, 15);
		curSSPanel_1.add(lblFirearmsCost);
		
		lblMedicineCost = new JLabel("");
		lblMedicineCost.setBounds(490, 220, 75, 15);
		curSSPanel_1.add(lblMedicineCost);
		
		lblMachinesCost = new JLabel("");
		lblMachinesCost.setBounds(490, 250, 75, 15);
		curSSPanel_1.add(lblMachinesCost);
		
		lblNarcoticsCost = new JLabel("");
		lblNarcoticsCost.setBounds(490, 280, 75, 15);
		curSSPanel_1.add(lblNarcoticsCost);
		
		lblRobotsCost = new JLabel("");
		lblRobotsCost.setBounds(490, 310, 75, 15);
		curSSPanel_1.add(lblRobotsCost);
		
		JPanel systemPanel = new JPanel();
		systemPanel.setBounds(0, 340, 943, 188);
		panel_7.add(systemPanel);
		systemPanel.setLayout(null);
		
		lblSolarSystem2_1 = new JLabel("Target Solar System:");
		lblSolarSystem2_1.setBounds(350, 10, 300, 18);
		systemPanel.add(lblSolarSystem2_1);
		
		lblResource_1 = new JLabel("Resource: ");
		lblResource_1.setBounds(350, 30, 300, 18);
		systemPanel.add(lblResource_1);
		
		lblGovernment_1 = new JLabel("Government: ");
		lblGovernment_1.setBounds(350, 50, 300, 18);
		systemPanel.add(lblGovernment_1);
		
		lblPolice_1 = new JLabel("Police: ");
		lblPolice_1.setBounds(350, 70, 300, 18);
		systemPanel.add(lblPolice_1);
		
		lblPirates_1 = new JLabel("Pirates: ");
		lblPirates_1.setBounds(350, 90, 300, 18);
		systemPanel.add(lblPirates_1);
		
		lblDistance_1 = new JLabel("Distance: ");
		lblDistance_1.setBounds(350, 150, 300, 18);
		systemPanel.add(lblDistance_1);
		
		lblTechLevel_1 = new JLabel("Tech Level: ");
		lblTechLevel_1.setBounds(350, 110, 300, 18);
		systemPanel.add(lblTechLevel_1);
		
		lblSizeTiny_1 = new JLabel("Size: ");
		lblSizeTiny_1.setBounds(350, 130, 300, 18);
		systemPanel.add(lblSizeTiny_1);
		
		lblCurrentSolarSystem = new JLabel("Current Solar System:");
		lblCurrentSolarSystem.setBounds(15, 10, 300, 18);
		systemPanel.add(lblCurrentSolarSystem);
		
		lblResource_2 = new JLabel("Resource:");
		lblResource_2.setBounds(15, 30, 300, 18);
		systemPanel.add(lblResource_2);
		
		lblGovernment_2 = new JLabel("Government:");
		lblGovernment_2.setBounds(15, 50, 300, 18);
		systemPanel.add(lblGovernment_2);
		
		lblPolice_2 = new JLabel("Police:");
		lblPolice_2.setBounds(15, 70, 300, 18);
		systemPanel.add(lblPolice_2);
		
		lblPirates_2 = new JLabel("Pirates:");
		lblPirates_2.setBounds(15, 90, 300, 18);
		systemPanel.add(lblPirates_2);
		
		lblTechLevel_2 = new JLabel("Tech Level:");
		lblTechLevel_2.setBounds(15, 110, 300, 18);
		systemPanel.add(lblTechLevel_2);
		
		lblSize = new JLabel("Size:");
		lblSize.setBounds(15, 130, 300, 18);
		systemPanel.add(lblSize);
		
		lblFuelLevel = new JLabel("Fuel Level:");
		lblFuelLevel.setBounds(15, 150, 300, 18);
		systemPanel.add(lblFuelLevel);
		
		btnWarp = new JButton("Warp");
		btnWarp.setBounds(487, 126, 117, 29);
		btnWarp.setEnabled(false);
		systemPanel.add(btnWarp);
		btnWarp.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				player.getShip().updateFuelFromTravel(currentSystem, targetSystem, player);
				updateSolarSystem(targetSystem);
				System.out.println(player.getShip().getFuel());
				System.out.println(player.getShip().getFuel());
				lblFuelLevel.setText("Fuel Level: " + player.getShip().getFuel() + "/" + player.getShip().getMaxFuel());
				updateMarketPlace(player);
				chartPanel.setCurrSystem(currentSystem);
				chartPanel.setTargSystem(null);
				chartPanel.repaint();
			}
		} );
		
		
		
	}
	
	/**
	 * Gets data of the player
	 * @return The player object
	 */
	public Player getPlayer() {
		return player;
	}
	public ShortRangeChart getChartPanel() {
		return chartPanel;
	}
	
	/**
	 * Sets the data of the player within the GUI by getting the player data of the object created by users.
	 * @param player The player object for the GUI
	 */
	public void setPlayer(Player player) {
		this.player = player;
		lblPlayername.setText("Player: " + player.getName());
		lblCredits.setText("Credits: "+player.getCredits());
		makeShortRangeChart();
	}
	
	/**
	 * This method generates the short range chart on the GUI.
	 */
	public void makeShortRangeChart() {
//<<<<<<< .mine
////		eastPanel = new ShortRangeChart(universe, this, player);
//		eastPanel = new JPanel();
//		mainPanel.add(eastPanel, BorderLayout.EAST);
//		eastPanel.setLayout(new GridLayout(2, 0, 4, 0));
//=======
		chartPanel = new ShortRangeChart(universe, this, player);
		chartPanel = new ShortRangeChart(universe, this, player);
		curSSPanel_1.add(chartPanel);
		chartPanel.setBounds(565, 30, 340, 340);
		chartPanel.setLayout(null);
		chartPanel.setVisible(true);

//		eastPanel.add(chartPanel);
	}
	
	/**
	 * Updates the marketplace when the player warps
	 * @param player The player object which contains data such as credits, cargo, ship, etc.
	 */
	public void updateMarketPlace(Player player) {
		lblCredits.setText("Credits: "+player.getCredits());
		int [] currentGoods = player.getShip().getGoods();
		btnSellWater.setText("" + currentGoods[0]);
		btnSellFurs.setText("" + currentGoods[1]);
		btnSellFood.setText("" + currentGoods[2]);
		btnSellOre.setText("" + currentGoods[3]);
		btnSellGames.setText("" + currentGoods[4]);
		btnSellFirearms.setText("" + currentGoods[5]);
		btnSellMedicine.setText("" + currentGoods[6]);
		btnSellMachines.setText("" + currentGoods[7]);
		btnSellNarcotics.setText("" + currentGoods[8]);
		btnSellRobots.setText("" + currentGoods[9]);
		if (currentSystem != null) {
			int [] systemGoods = currentSystem.getGoods();
			btnBuyWater.setText("" + systemGoods[0]);
			btnBuyFurs.setText("" + systemGoods[1]);
			btnBuyFood.setText("" + systemGoods[2]);
			btnBuyOre.setText("" + systemGoods[3]);
			btnBuyGames.setText("" + systemGoods[4]);
			btnBuyFirearms.setText("" + systemGoods[5]);
			btnBuyMedicine.setText("" + systemGoods[6]);
			btnBuyMachines.setText("" + systemGoods[7]);
			btnBuyNarcotics.setText("" + systemGoods[8]);
			btnBuyRobots.setText("" + systemGoods[9]);
			lblWaterPrice.setText("" + sellPrices[0]);
			lblFursPrice.setText("" + sellPrices[1]);
			lblFoodPrice.setText("" + sellPrices[2]);
			lblOrePrice.setText("" + sellPrices[3]);
			lblGamesPrice.setText("" + sellPrices[4]);
			lblFirearmsPrice.setText("" + sellPrices[5]);
			lblMedicinePrice.setText("" + sellPrices[6]);
			lblMachinesPrice.setText("" + sellPrices[7]);
			lblNarcoticsPrice.setText("" + sellPrices[8]);
			lblRobotsPrice.setText("" + sellPrices[9]);
			lblWaterCost.setText("" + buyPrices[0]);
			lblFursCost.setText("" + buyPrices[1]);
			lblFoodCost.setText("" + buyPrices[2]);
			lblOreCost.setText("" + buyPrices[3]);
			lblGamesCost.setText("" + buyPrices[4]);
			lblFirearmsCost.setText("" + buyPrices[5]);
			lblMedicineCost.setText("" + buyPrices[6]);
			lblMachinesCost.setText("" + buyPrices[7]);
			lblNarcoticsCost.setText("" + buyPrices[8]);
			lblRobotsCost.setText("" + buyPrices[9]);
		}
	}
	
	/**
	 * Updates the target system information as the user clicks different systems.
	 * @param system
	 */
	public void updateTargetSystem(SolarSystem system) {
		targetSystem = system;
		if(chartPanel.inRange(currentSystem, system)) {
			btnWarp.setEnabled(true);
			chartPanel.repaint();
		} else btnWarp.setEnabled(false);
	}
	
	/**
	 * Updates the solar system after warping.
	 */
	public void updateSolarSystem() {
		Random rand = new Random();
		if (currentSystem == null) {
			currentSystem = universe.get(rand.nextInt(universe.size()));
			updateMarketPlace(player);
		}
		lblSolarSystem.setText("Solar System: " + currentSystem.getName());
		lblCurrentSolarSystem.setText("Current Solar System: " + currentSystem.getName());
		lblResource_2.setText("Resource: " + currentSystem.getResource());
		lblGovernment_2.setText("Government: " + currentSystem.getGovernment());
	//	lblPolice_2.setText("Police: " + currentSystem.getPoliceLevel());
	//	lblPirates_2.setText("Pirates: " + currentSystem.getPirateLevel());
		lblTechLevel_2.setText("Tech Level: " + currentSystem.getTechLevelName());
		lblSize.setText("Size: " + currentSystem.getSize());
		lblFuelLevel.setText("Fuel Level: " + player.getShip().getFuel() + "/" + player.getShip().getMaxFuel());
	//  lblPolice.setText("Police: " + targetSystem.getPoliceLevel());
	//  lblPirates.setText("Pirates: " + targetSystem.getPirateLevel());
		if (targetSystem != null) {
			lblSolarSystem2_1.setText("Target Solar System: " + targetSystem.getName());
			lblResource_1.setText("Resource: " + targetSystem.getResource());
			lblGovernment_1.setText("Government: " + targetSystem.getGovernment());
			lblTechLevel_1.setText("Tech Level: " + targetSystem.getTechLevelName());
			lblSizeTiny_1.setText("Size: " + targetSystem.getSize());
			lblDistance_1.setText("Distance: " + currentSystem.getDistance(targetSystem));
		}
		String event;
		if (rand.nextInt(100)<10){
			int index = rand.nextInt(7);
			String[] array = {"Lack of Workers","Boredom","Plague","War","Cropfail","Cold","Drought"};
			event = array[index];
		}
		else{
			event = "None";
		}
		mpLogic = new MarketPlaceLogic(currentSystem, event);
		buyPrices = mpLogic.buyPrices();
		sellPrices = mpLogic.sellPrices();
		
	}
	
	/**
	 * Updates the Solar System every time someone warps.
	 * @param currentSystem The current system that the user is on.
	 */
	public void updateSolarSystem(SolarSystem currentSystem) {
		Random rand = new Random();
		if (this.currentSystem == null) {
			this.currentSystem = universe.get(rand.nextInt(universe.size()));
			updateMarketPlace(player);
		} else {
			this.currentSystem = currentSystem;
			updateMarketPlace(player);
		}
		lblSolarSystem.setText("Solar System: " + currentSystem.getName());
		lblCurrentSolarSystem.setText("Current Solar System: " + currentSystem.getName());
		lblResource_2.setText("Resource: " + currentSystem.getResource());
		lblGovernment_2.setText("Government: " + currentSystem.getGovernment());
	//	lblPolice_2.setText("Police: " + currentSystem.getPoliceLevel());
	//	lblPirates_2.setText("Pirates: " + currentSystem.getPirateLevel());
		lblTechLevel_2.setText("Tech Level: " + currentSystem.getTechLevelName());
		lblSize.setText("Size: " + currentSystem.getSize());
		lblFuelLevel.setText("Fuel Level: " + player.getShip().getFuel() + "/" + player.getShip().getMaxFuel());
	//  lblPolice.setText("Police: " + targetSystem.getPoliceLevel());
	//  lblPirates.setText("Pirates: " + targetSystem.getPirateLevel());
		if (targetSystem != null) {
			lblSolarSystem2_1.setText("Target Solar System: " + targetSystem.getName());
			lblResource_1.setText("Resource: " + targetSystem.getResource());
			lblGovernment_1.setText("Government: " + targetSystem.getGovernment());
			lblTechLevel_1.setText("Tech Level: " + targetSystem.getTechLevelName());
			lblSizeTiny_1.setText("Size: " + targetSystem.getSize());
			lblDistance_1.setText("Distance: " + currentSystem.getDistance(targetSystem));
		}
		String event;
		if (rand.nextInt(100)<10){
			int index = rand.nextInt(7);
			String[] array = {"Lack of Workers","Boredom","Plague","War","Cropfail","Cold","Drought"};
			event = array[index];
		}
		else{
			event = "None";
		}
		mpLogic = new MarketPlaceLogic(currentSystem, event);
		buyPrices = mpLogic.buyPrices();
		sellPrices = mpLogic.sellPrices();
		chartPanel.setCurrSystem(currentSystem);
		chartPanel.setTargSystem(targetSystem);
	}
	
	/**
	 * A getter for the GUI itself (and all of the data within it)
	 * @return The GUI
	 */
	public SolarSystem getCurrentSystem() {
		return currentSystem;
	}
	private SpaceTraderGui getGui() {
		return this;
	}
}
